/*
Copyright 2009 Peter Krajnc, SCREENWORKER

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.screenworker.compactmvc.examples.flex
{
	import com.screenworker.compactmvc.examples.flex.common.ApplicationConstants;
	import com.screenworker.compactmvc.examples.flex.controller.ApplicationCompleteCommand;
	import com.screenworker.compactmvc.examples.flex.controller.CreationCompleteCommand;
	import com.screenworker.compactmvc.examples.flex.controller.DeleteCurrentDocumentCommand;
	import com.screenworker.compactmvc.examples.flex.controller.GetDescriptonCommand;
	import com.screenworker.compactmvc.examples.flex.controller.LoadModuleCommand;
	import com.screenworker.compactmvc.examples.flex.controller.LoadModuleCompleteCommand;
	import com.screenworker.compactmvc.examples.flex.controller.LoadXMLCompleteCommand;
	import com.screenworker.compactmvc.examples.flex.controller.ModuleCleanupCommand;
	import com.screenworker.compactmvc.examples.flex.controller.NewDocumentCommand;
	import com.screenworker.compactmvc.examples.flex.controller.PreinitializeCommand;
	import com.screenworker.compactmvc.examples.flex.controller.ReceiveMessageCommand;
	import com.screenworker.compactmvc.examples.flex.controller.RemotingResultCommand;
	import com.screenworker.compactmvc.examples.flex.controller.RemoveModuleCommand;
	import com.screenworker.compactmvc.examples.flex.controller.SelectDocumentCommand;
	import com.screenworker.compactmvc.examples.flex.controller.SendMessageCommand;
	import com.screenworker.compactmvc.examples.flex.controller.UpdateViewCommand;
	import com.screenworker.compactmvc.examples.flex.controller.ViewRegisterCommand;
	import com.screenworker.compactmvc.examples.flex.controller.ViewRemoveCommand;
	import com.screenworker.compactmvc.examples.flex.model.ApplicationViewModel;
	import com.screenworker.compactmvc.examples.flex.model.RemotingModel;
	import com.screenworker.compactmvc.examples.flex.model.XmlModel;
	import com.screenworker.compactmvc.interfaces.IController;
	import com.screenworker.compactmvc.patterns.Controller;
	
	import mx.events.FlexEvent;

	public class ApplicationController extends Controller implements IController
	{
		public static const NAME:String = 'ApplicationController';
		
		// --- Notification Types ---
		public static const NEW_DOCUMENT:String 			= 'newDocument';
		public static const REMOVE_CURRENT_DOCUMENT:String 	= 'removeCurrentDocument';
		public static const DOCUMENT_SELECT:String 			= 'documentSelect';
		public static const LOAD_MODULE:String 				= 'loadModule';
		public static const REMOVE_MODULE:String 			= 'removeModule';
		public static const UPDATE_VIEW:String				= 'updateView';
		public static const SEND_MESSAGE:String				= 'sendMessage';
		public static const LOADXML_COMPLETE:String			= 'loadXMLComplete';
		public static const GET_DESCRIPTION:String			= 'getDescription';
		public static const REMOTING_RESULT:String			= 'remotingResult';
		
		public function ApplicationController()
		{
			super(NAME);	
		}
		
		/**
		 * commands and models should be registered once the controller has been registered 
		 * 
		 */		
		override public function registerHandler():void
		{
			//register models
			registerModel(ApplicationViewModel.NAME, ApplicationViewModel);
			registerModel(XmlModel.NAME, XmlModel);
			registerModel(RemotingModel.NAME, RemotingModel);
			
			//handle flex events
			registerCommand(FlexEvent.PREINITIALIZE, PreinitializeCommand);
			registerCommand(FlexEvent.APPLICATION_COMPLETE, ApplicationCompleteCommand);
			registerCommand(FlexEvent.CREATION_COMPLETE, CreationCompleteCommand);
			
			//document commands
			registerCommand(NEW_DOCUMENT, NewDocumentCommand);	
			registerCommand(REMOVE_CURRENT_DOCUMENT, DeleteCurrentDocumentCommand);
			registerCommand(DOCUMENT_SELECT, SelectDocumentCommand);		
			registerCommand(UPDATE_VIEW, UpdateViewCommand);
			registerCommand(ApplicationConstants.SEND_MESSAGE_TO_SHELL, ReceiveMessageCommand);
			registerCommand(VIEW_REGISTER, ViewRegisterCommand);
			registerCommand(VIEW_REMOVE, ViewRemoveCommand);
			registerCommand(LOADXML_COMPLETE, LoadXMLCompleteCommand);
			registerCommand(GET_DESCRIPTION, GetDescriptonCommand);
			registerCommand(REMOTING_RESULT, RemotingResultCommand);
			
			//module commands
			registerCommand(LOAD_MODULE, LoadModuleCommand);
			registerCommand(REMOVE_MODULE, RemoveModuleCommand);
			registerCommand(ApplicationConstants.SEND_CLEANUP_COMPLETE_TO_SHELL, ModuleCleanupCommand);
			registerCommand(SEND_MESSAGE, SendMessageCommand);
			registerCommand(ApplicationConstants.SEND_MODULE_COMPLETE_TO_SHELL, LoadModuleCompleteCommand);	
		}
	}
}
